package com.block.account.factory;

import com.block.account.enums.AccountTypeEnum;
import com.block.account.service.IAccountActionHandleService;
import com.block.account.service.impl.AccountInfoServiceImpl;
import com.block.account.service.impl.AccountItemChannleServiceImpl;
import com.block.account.service.impl.AccountItemProductServiceImpl;
import com.block.account.service.impl.AccountItemSpecialServiceImpl;
import com.block.common.util.ApplicationContextUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 根据账户类型不同，进行的不同处理
 */
public class AccountFactory {

    private static Map<String, Class<? extends IAccountActionHandleService>> serviceMap = new HashMap<>();
    static {
        serviceMap.put(AccountTypeEnum.CHAN.getValue(), AccountItemChannleServiceImpl.class);
        serviceMap.put(AccountTypeEnum.PROD.getValue(), AccountItemProductServiceImpl.class);
        serviceMap.put(AccountTypeEnum.SPECIAL.getValue(), AccountItemSpecialServiceImpl.class);
        serviceMap.put(AccountTypeEnum.ACCOUNT.getValue(), AccountInfoServiceImpl.class);
    }

    public static IAccountActionHandleService getService(String type){
        if (serviceMap.containsKey(type)){
            Class<? extends IAccountActionHandleService> aClass = serviceMap.get(type);
            return ApplicationContextUtil.getBean(aClass);
        }
        return null;
    }
}
